package config

import (
	"fmt"
	"time"
)

type MysqlConfig struct {
	Host                   string        `json:"host"`
	Port                   string        `json:"port"`
	Username               string        `json:"username"`
	Password               string        `json:"password"`
	Database               string        `json:"database"`
	KeepConnectionDuration time.Duration `json:"keep_connection_duration"`
	MaxOpenConnections     int           `json:"max_open_connections"`
	MaxIdleConnections     int           `json:"max_idle_connections"`
}

func Mysql() *MysqlConfig {
	return &MysqlConfig{
		Host:                   "127.0.0.1",
		Port:                   "3306",
		Username:               "root",
		Password:               "root",
		Database:               "ecms",
		KeepConnectionDuration: time.Second * 30,
		MaxOpenConnections:     50,
		MaxIdleConnections:     50,
	}
}

func (c *MysqlConfig) Dsn() string {
	return fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8&parseTime=True&loc=Local", c.Username, c.Password, c.Host, c.Port, c.Database)
}
